<?php

/*
 * @author 704993132@qq.com
 * @function 加载导航网站首页
 */

class HomePageAction extends CommonAction {

    /**
     * 加载分类和分类下面的品牌
     */
    public function loadCategoryAndBrand() {
           $gw_category = M('Gw_category');
        // $categoryList = $gw_category->select();

        $aArray = array();
        $bArray = array();
        $aList = $gw_category->where('level=1')->order('id')->select();
        $bList = $gw_category->where('level=2')->order('id')->select();
        $categoryBrand = D('CategoryBrandView');
        $where['b.positionFlag'] = '1';
        $cList = $categoryBrand->where($where)->select();

        for ($j = 0; $j < count($bList); $j++) {
            for ($k = 0; $k < count($cList); $k++) {
                if ($cList[$k]['categoryId'] == $bList[$j]['id']) {
                    $bArray[$bList[$j]['name']][] = $cList[$k];
                }
            }
        }


        for ($i = 0; $i < count($aList); $i++) {
            for ($j = 0; $j < count($bList); $j++) {
                if ($bList[$j]['parentId'] == $aList[$i]['id']) {
                    $aArray[$aList[$i]['name']][] = $bList[$j];
                }
            }
        }

        var_dump($aArray);
        var_dump($bArray);
        $this->assign('aArray', $aArray);
        $this->assign('bArray', $bArray);
        $this->display();
    }

    /**
     * 加载首页主推荐部分的品牌
     */
    public function loadHeadTopBrand() {
        $headTop = D('HeadTopView');
        $where['b.positionFlag'] = '0';
        $headTopList = $headTop->where($where)->order('id')->select();
        
        echo $headTop->getlastsql();

        $headTopMarketList = array();
        for ($i = 0; $i < count($headTopList); $i++) {
            $headTopMarketList[$headTopList[$i]['id']][] = $headTopList[$i];
        }
        //var_dump($headTopMarketList);
        //var_dump($headTopList);
        $this->assign('headTopMarketList', $headTopMarketList);
        $this->display();
    }


    /**
     * 加载品牌故事
     */
    public function loadBrandStory() {
        $todayDate = date("Y-m-d");
        $gw_displayRule = M('Gw_displayRule');
        $map['storyStart'] = array('elt', $todayDate);
        $map['storyEnd'] = array('egt', $todayDate);
        $gw_displayRule->where($map)->find();
        $model = new Model();
        $brandStory = $model->table('gw_brandStory bs,gw_brand b')
                ->where('bs.brandId=b.id and bs.brandId=' . $gw_displayRule['brandStoryId'])
                ->field('gw_brandStory.*,gw_brand.*')
                ->find();
        $this->assign('brandStory', $brandStory);
        $this->display();
    }

    /**
     * 加载十大品牌
     */
    public function loadTopTen() {
        $model = new Model();
        $topList = $model->table('gw_top10 t,gw_brand b')
                ->where('t.brandId=b.id')
                ->field('gw_top10.*,gw_brand.*')
                ->order('gw_top10.rank')
                ->select();

        $this->assign('topList', $topList);
        $this->display();
    }

}

?>
